package com.wl.eb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.eb.mapper.EbCommentMapper;
import com.wl.eb.module.EbComment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class CommentService {
    @Resource
    private EbCommentMapper ebCommentMapper;

    public Page list(int psize){
        Page page = new Page(psize, 5);
        Page commentpage = ebCommentMapper.selectPage(page, new QueryWrapper<EbComment>()
                .orderByDesc("ec_create_time"));
        return commentpage;
    }

    public boolean save(EbComment ebComment){
       //添加 时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        ebComment.setEcCreateTime(sdf.format(new Date()));
        //添加留言
        int result= ebCommentMapper.insert(ebComment);
        return result>0?true:false;
    }

    public EbComment detail(int commentId){
        return ebCommentMapper.selectById(commentId);
    }
}
